import 'package:fate_blind_box/ui/main/navigator.dart';
import 'package:fate_blind_box/utils/provider.dart';
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';

import 'login_by_pwd.dart';
import 'login_wechat.dart';
//引导页
class GuidePage extends StatefulWidget {
  const GuidePage({Key? key}) : super(key: key);

  @override
  _GuidePageState createState() => _GuidePageState();
}

class _GuidePageState extends State<GuidePage>
    with SingleTickerProviderStateMixin {
  late PageController _pageController;
  bool isVisible = true;
  TabController? _tabController;

  @override
  void initState() {
    // TODO: implement initState
    super.initState();
    _pageController =  PageController();
    _tabController =  TabController(initialIndex: 0, length: 3, vsync: this);
    _tabController?.addListener(() {
      if (_tabController?.index == 2) {
        setState(() {
          isVisible = false;
        });
      } else {
        setState(() {
          isVisible = true;
        });
      }

    });
  }

  final List<Widget> listImage = [
    Image.asset(
      "images/ic_yd_xyxq.png",
      fit: BoxFit.fill,
      width: double.infinity,
      height: double.infinity,
    ),
    Image.asset(
      "images/ic_yd_yysj.png",
      fit: BoxFit.fill,
      width: double.infinity,
      height: double.infinity,
    ),
    Image.asset(
      "images/ic_yd_axhz.png",
      fit: BoxFit.fill,
      width: double.infinity,
      height: double.infinity,
    ),

  ];

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: Stack(
        children: [
          TabBarView(
            controller: _tabController,
            children: [
              listImage[0],
              listImage[1],
              Stack(
                children: [
                  listImage[2],
                  Container(
                    margin: const EdgeInsets.only(bottom: 80),
                    child: Align(
                      alignment: Alignment.bottomCenter,
                      child: InkWell(
                        onTap: (){
                          if(Provider.token.isNotEmpty){
                            Navigator.of(context).push(MaterialPageRoute(builder: (ctx) =>  AppMain()));
                          }else{
                            if(kIsWeb) {
                              Navigator.of(context).push(MaterialPageRoute(builder: (ctx) => const LoginByWechat()));
                            } else {
                              Navigator.of(context).push(MaterialPageRoute(builder: (ctx) => const LoginByPwd()));
                            }
                          }

                        },
                        child: Container(
                          width: 150,
                          height: 40,
                          alignment: Alignment.center,
                          decoration: BoxDecoration(
                              color: const Color(0xff7F69D9),
                              borderRadius: BorderRadius.circular(40)),
                          child: const Text("欢迎使用App",style: TextStyle(color: Colors.white),),
                        ),
                      ),
                    ),
                  )
                ],
              ),
            ],
          ),
          // Visibility(
          //     visible: isVisible,
          //     child: Container(
          //       margin: EdgeInsets.only(bottom: 40),
          //       child: Align(
          //         alignment: Alignment.bottomCenter,
          //         child: TabPageSelector(
          //           controller: _tabController,
          //           selectedColor: Colors.amberAccent,
          //           indicatorSize: 17,
          //           color: Colors.black12,
          //         ),
          //       ),
          //     ))
        ],
      ),
    );
  }
}
